package com.account.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.account.dao.RegistrationDAO;
import com.account.validate.RegistrationValidator;

/**
 * Servlet implementation class RegistrationServlet
 */
@WebServlet("/RegistrationServlet")
public class Registration extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Registration() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@SuppressWarnings({ "deprecation", "unused" })
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("Text/html");	
		PrintWriter out=response.getWriter();
			String firstname=request.getParameter("firstname");
			String lastname=request.getParameter("lastname");
		
			
			String fathername=request.getParameter("fathername");
			String thikana=request.getParameter("thikana");
			String qualification=request.getParameter("qualification");
			String status=request.getParameter("status");
			Long contactno=Long.parseLong((request.getParameter("contactno")));
			String emailid=request.getParameter("emailid");
			Date joinDate=null;
			Date dob = null;
			try {
				SimpleDateFormat dateFormat=new SimpleDateFormat("mm/dd/yyyy");
				 dob = dateFormat.parse(request.getParameter("date"));
				 String s=request.getParameter("joiningdate");
				 joinDate = dateFormat.parse(s);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
			RegistrationValidator regvalidator=new RegistrationValidator();
			/*boolean b=regvalidator.isUserDetail(firstname, lastname, thikana, fathername, status, qualification);
			
				if(b){
					out.println(firstname);
					out.println(qualification);
					out.println(status);
				
					out.println(emailid);
				} else{
				
				out.println("Re-Enter Valid Entry For fields");
			}
				boolean
			 b1=regvalidator.isEmailValidator(emailid);
				if(b1){
			out.println(emailid);
				}else{
					out.println(emailid);
				}*/
			/*out.println("bfeore vlidation : "+firstname);
			String name=regvalidator.setFirstName(firstname);
			out.println("after vlidation : "+firstname);
			out.println(name);*/
			//out.println("Transaction Saved Successfull");
			RegistrationDAO registrationDAO=new RegistrationDAO();
			boolean b=registrationDAO.setRegistration(firstname, lastname, dob, fathername, thikana, qualification, status, contactno, emailid, joinDate);
			if(b){
				
				out.println("Transaction UnSuccessfull");
			}else{
				out.println("Transaction Saved Successfully");
			}
			
			
	
	}
}
